package com.webchat.ugc.repository.dao;

import com.webchat.ugc.repository.entity.mall.im.MallChatAccountEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;


@Repository
public interface IMallChatAccountDAO extends JpaSpecificationExecutor<MallChatAccountEntity>,
                                             JpaRepository<MallChatAccountEntity, Long> {


    int countAllByAccountAndChatAccountAndDeleted(String account, String chatAccount, Boolean deleted);

    @Query(value = "update MallChatAccountEntity mca " +
                   "set mca.deleted = true " +
                   "where mca.account = :account and mca.chatAccount = :chatAccount")
    int deleteAllByAccountAndChatAccount(String account, String chatAccount);

    @Query(value = "update MallChatAccountEntity mca " +
            "set mca.lastChatDate = :lastChatDate " +
            "where mca.account = :account and mca.chatAccount = :chatAccount")
    int updateChatAccountLastChatTime(String account, String chatAccount, Date lastChatDate);

    List<MallChatAccountEntity> findAllByAccountAndDeleted(String account, Boolean deleted);
}